import { defineStore } from 'pinia'
import {webInfoApi} from "@/api/blog/webInfoApi.ts";

// 第一个参数是应用程序中 store 的唯一 id
export const webInfoStore = defineStore('webInfo', {
    // 推荐使用 完整类型推断的箭头函数
    state: ()=> {
        return {
            title: '',
            description: '',
            copyright: '',
            icp: '',
            avatar: '',
            nickname: '',
            signature: '',
            webLinkInfo: [] as Link[],
            frontendStack: [] as string[],
            backendStack: [] as string[],
            database: '',
            server: '',
            deployUrl: '',
            websiteInfo: '',
            statistics: {} as Statistics,
            deployTime: '', // 部署时间 格式：yyyy-MM-dd HH:mm:ss
            system: '' // 系统
        } as WebInfo
    },
    getters: {
        getWebInfo: (state) => {
            return state
        },
        getWebLinkInfo : (state) => {
            return state.webLinkInfo
        },
        getWebInfoTitle : (state) => {
            return state.title
        },
        getAvatar : (state) => {
            return state.avatar
        },
        getNickname : (state) => {
            return state.nickname
        },
        getSignature : (state) => {
            return state.signature
        },
        getStatistics : (state) => {
            return state.statistics
        },
        getDeployTime : (state) => {
            return state.deployTime
        },
        getCopyright: (state) => {
            return state.copyright
        },
        getIcpInfo: (state) => {
            return state.icp
        },
        getFrontendStack: (state) => {
            return state.frontendStack
        },
        getBackendStack: (state) => {
            return state.backendStack
        },
        getDeployUrl: (state) => {
            return state.deployUrl
        },
    },
    actions: {
        async initWebInfo() {
            webInfoApi.getWebInfo().then((res) => {
                this.$state = res.data
            })
        },
        setWebInfo(webInfo:WebInfo) {
            this.$patch(webInfo)
        }
    },
    // 表示这个store里的数据都将持久化存储
    persist: true
})
